#ifndef __ITKEXT__IMAGE__MOMENTSCALCULATOR__H__
#define __ITKEXT__IMAGE__MOMENTSCALCULATOR__H__

#include <itkMatrix.h>
#include <itkPoint.h>

namespace itkExt
{
  /**
   * Based on itkImageMomentsCalculator
   */
  template< class S, unsigned int D >
  class MomentsCalculator
  {
  public:
    typedef MomentsCalculator              Self;
    typedef S                              TScalar;
    typedef itk::Matrix< S, D, D >         TMatrix;
    typedef itk::Matrix< S, D + 1, D + 1 > THMatrix;
    typedef itk::Point< S, D >             TPoint;
    typedef typename TPoint::VectorType    TVector;

  public:
    MomentsCalculator( );
    virtual ~MomentsCalculator( ) { }

    void Reset( );
    void AddMass( const TPoint& pnt, const TScalar& mass );
    void AddMass( const TVector& vec, const TScalar& mass );

    void Compute( );
    void AlignProperMatrix( const TVector& dir );
    void AlignProperMatrix( const TMatrix& rot );

    const TScalar& GetMass        ( ) const { return( this->m_Mass ); }
    const TVector& GetCenter      ( ) const { return( this->m_Center ); }
    const TVector& GetOffset      ( ) const { return( this->m_Center ); }
    const TMatrix& GetInertia     ( ) const { return( this->m_Inertia ); }
    const TVector& GetProperValues( ) const { return( this->m_PValues ); }
    const TMatrix& GetProperMatrix( ) const { return( this->m_PMatrix ); }

    THMatrix GetHomogeneousMatrix( ) const;

  protected:
    bool m_Updated;

    TScalar m_Mass;
    TVector m_As;
    TMatrix m_Gs;

    TVector m_Center;
    TMatrix m_Inertia;
    TVector m_PValues;
    TMatrix m_PMatrix;
  };

} // ecapseman

#include <itkExtMomentsCalculator.txx>

#endif // __ITKEXT__IMAGE__MOMENTSCALCULATOR__H__

// eof - $RCSfile: itkExtMomentsCalculator.h,v $
